﻿<%
'''核心入口类
Class Ashapo_Sa_Class
	'RegExp对象
	Private s_regex
	'''运行代码的前修饰符,一般为变量定义
	Private s_vcodepre
	'''include的文件及代码(头部)遵循规定：先开始后结束，后开始先结束
	Private s_inccodepre
	'''include的代码(底部)
	Private s_inccodefix
	'''页面跳转标题,提示信息,跳转等待时间(秒),跳转页面地址
	Private s_msgTitle, s_message, s_waitSecond, s_jumpUrl
	'''Ecore/Use/Extends的析构触发代码段,编译的一致顺序是先进后出
	Private s_codefix
	'''当前G/M/A/T
	Private s_nowG, s_nowM, s_nowA, s_nowT
	'''可运行缓存文件路径/data/_cache/_run/home/index_index.asp
	Private s_vcp
	'''action类文件路径/app/Action/home/indexAction.class.asp
	Private s_vfp
	'''处理后的缓存action类文件路径/data/_cache/_action/home/indexAction.class.asp
	Private s_ccp
	'''模板路径,用于Tpl.Display过程/app/Tpl/default/home/index/index.html
	Private s_vtp
	'''进行的数据库查询次数
	Public DbQueryTimes
	'''核心使用的Err/Fso/Log/Tpl/Http类(使用特征命名)
	Public [E],[Fso],[Log],[Tpl],[Http]
	
	'''构造
	Private Sub Class_Initialize()
		s_vcodepre = ""
		s_inccodepre = ""
		s_inccodefix = ""
		Set s_regex = New RegExp
		s_regex.Global = True
		s_regex.IgnoreCase = True
		s_regex.Multiline = False
		s_msgTitle = ""
		s_message = ""
		s_waitSecond = 3
		s_jumpUrl = ""
		s_codefix = ""
		'获取GMAL信息
		s_nowG = G("g:s:" & C_DefGroup)
		s_nowM = G("m:s:" & C_DefModule)
		s_nowA = G("a:s:" & C_DefAction)
		s_nowT = C_DefTplName
		s_vcp = "/" & C_DataFolder & "/" & C_CacheFolder & "/_run/" & s_nowG & "/" & s_nowM & C_CacheFit & s_nowA & ".asp"
		DbQueryTimes = 0
	End Sub
	
	'''析构Err/Fso/Log/Tpl类
	Private Sub Class_Terminate()
		'在这里进行Ecore/Use/Extends的析构函数
		If s_codefix <> "" Then
			ExecuteGlobal(s_codefix)
		End If
		'析构核心
		'If Has([E]) Then
			Set [E] = Nothing
		'End If
		'If Has([Fso]) Then
			Set [Fso] = Nothing
		'End If
		'If Has([Log]) Then
			Set [Log] = Nothing
		'End If
		'If Has([Tpl]) Then
			Set [Tpl] = Nothing
		'End If
		Set s_regex = Nothing
	End Sub
	
	'''构建HTML缓存位置
	Private Function htmlPath_()
		Dim t_p : t_p = "/" & C_DataFolder & "/html/" & s_nowG & "/" & s_nowM & "/" & s_nowA & "/"
		Dim t_k
		'所有GET参数(不含GMA及标识位)
		For Each t_k In Request.QueryString
			If t_k<>"g" And t_k<>"m" And t_k<>"a" And t_k<>C_DisHtmlFit Then
				t_p = t_p & t_k & "-" & Request.QueryString(t_k) & "_"
			End If
		Next
		t_p = Left(t_p, Len(t_p)-1)
		t_p = t_p & ".html"
		htmlPath_ = t_p
	End Function
	
	'''设置是否进行当前页面HTML静态缓存
	'(在页面渲染前设置都有效,可以进行逻辑判断生成)
	'设置该属性为True时即可以对当前页面进行缓存
	'对应缓存页面应是在多次运行时无逻辑变动(因为使用HTTP进行了二次访问,当然,既然进行了HTML缓存那肯定就是因为无逻辑变动)
	'内置一个特殊的GET值,用于判断是否要进行HTML静态化(防止死循环)
	'p_b:布尔值,是否生成HTML
	Public Property Let HTML(Byval p_b)
		If p_b Then
			'Response.Write("OK")
			'Response.End
			'标识位为空时则进行HTML缓存
			If Request.QueryString(C_DisHtmlFit)="" Then
				'HTML缓存位置
				Dim t_hp : t_hp = htmlPath_()
				'HTML缓存清空交由Tool类和程序逻辑完成
				If Not isFile_(t_hp) Then
					'访问当前已缓存的asp运行文件
					'Response.Write(t_hp)
					'Response.End
					If isFile_(s_vcp) Then
						buildCore_("Http,Fso")
						[Http].Url = s_vcp & "?" & Request.QueryString & "&" & C_DisHtmlFit & "=1"
						Dim t_h : t_h = [Http].Open()
						'保存到HTML文件夹
						Call [Fso].CreateFile(t_hp, t_h, True)
					End If
				End If
			End If
		End If
	End Property
	
	'''设置缓存记录(Application)
	'p_n:缓存名称
	'p_d:缓存值
	Public Sub SetApp(Byval p_n,Byref p_d)
		Application.Lock
		If IsObject(p_d) Then
			Set Application(p_n) = p_d
		Else
		Application(p_n) = p_d
		End If
		Application.UnLock
	End Sub

	'''获取一个缓存(Application)记录
	Public Function GetApp(Byval p_n)
		If IsN(p_n) Then
			GetApp = Empty : Exit Function
		End If
		If IsObject(Application(p_n)) Then
			Set GetApp = Application(p_n)
		Else
			GetApp = Application(p_n)
		End If
	End Function

	'''删除一个缓存记录(Application)
	Public Sub RemoveApp(ByVal p_n)
		Application.Lock
		Application(p_n) = Empty
		Application.UnLock
	End Sub

	'''清除缓存
	Public Sub ClearApp()
		Application.Contents.RemoveAll()
	End Sub
	
	'''获取系统设置(废弃)
	'Config("Debug") = IfHas(G_Debug,C_Debug)
	'p_c:去掉前缀的设置名称
	Public Function Config(Byval p_c)
		Config = Eval("IfHas(G_" & p_c & ", C_" & p_c& ")")
	End Function
	
	'''判断类代码中是否包含指定的公有函数
	'p_f:函数名称
	'p_s:代码段
	Private Function hasFunSub_(Byval p_f, Byval p_s)
		s_regex.Pattern = "[Public]?[\s]*[Sub|Function]{1}[\s]*[\[]?" & p_f & "[\]]?[\s]*\([^\)]*\)"
		If s_regex.Test(p_s) Then
			hasFunSub_ = True
		Else
			hasFunSub_ = False
		End If
	End Function

	'''获取实际路径MapPath(不支持通配符)
	'p_p:路径
	Private Function absPath_(Byval p_p)
		'On Error Resume Next
		If CStr(p_p) = "" Then
			absPath_ = "" : Exit Function
		End If
		If Mid(p_p,2,1)<>":" Then
			p_p = Server.MapPath(p_p)
		End If
		If Right(p_p,1) = "\" Then
			p_p = Left(p_p,Len(p_p)-1)
		End If
		absPath_ = p_p
		'If Err.Number<>0 Then
		'	Response.Write(p_p)
		'	Reponse.End()
		'End If
		'Err.Clear()
	End Function
	
	'''判断文件是否存在
	'p_p:文件路径
	Private Function isFile_(Byval p_p)
		p_p = absPath_(p_p)
		isFile_ = False
		Dim t_f
		Set t_f = Server.CreateObject(C_FsoName)
		If t_f.FileExists(p_p) Then
			isFile_ = True
		End If
		Set t_f = Nothing
	End Function
	
	'''读取服务器端文件内容
	'p_p:文件路径
	Private Function readFile_(Byval p_p)
		Dim t_s, t_t
		p_p = absPath_(p_p)
		If isFile_(p_p) Then
			Set t_s = Server.CreateObject("ADODB.Stream")
			With t_s
				.Type = 2
				.Mode = 3
				.Open
				.LoadFromFile p_p
				.Charset = "UTF-8"
				.Position = 2
				t_t = .ReadText
				.Close
			End With
			Set t_s = Nothing
			If RegTest(t_t,"^\uFEFF") Then
				t_t = RegReplace(t_t,"^\uFEFF","")
			End If
		Else
			t_t = ""
			'收集错误,Log信息收集(Err在首次解析时已经起效)
			[E].Raise(1)
		End If
		readFile_ = t_t
	End Function
	
	'''设置页面跳转标题
	'p_t:标题字符串
	Public Property Let MsgTitle(Byval p_t)
		s_msgTitle = p_t
	End Property
	
	'''设置页面跳转提示信息
	'p_m:提示信息字符串
	Public Property Let Message(Byval p_m)
		s_message = p_m
	End Property
	
	'''设置页面跳转等待时间(秒)
	'p_s:等待的秒数(数字)
	Public Property Let WaitSecond(Byval p_s)
		s_waitSecond = p_s
	End Property
	
	'''设置页面跳转页面地址
	'p_u:跳转的链接
	Public Property Let JumpUrl(Byval p_u)
		s_jumpUrl = p_u
	End Property
	
	'''由文件路径获取完整的include代码(包括内部再include)
	'p_p:文件路径
	Private Function incReadByFile_(Byval p_p)
		Dim t_c, t_m, t_rule, t_inc, t_incFile, t_incStr
		t_c = readFile_(p_p)
		If IsN(t_c) Then
			Exit Function
		End If
		t_c = RegReplace(t_c, "<"&"%"&" *?@.*?%"&">", "")
		t_c = RegReplace(t_c, "(<"&"%"&"[^>]+?)(option +?explicit)([^>]*?%"&">)", "$1'$2$3")
		t_rule = "<!-- *?#include +?(file|virtual) *?= *?""??([^"":?*\f\n\r\t\v]+?)""?? *?-->"
		If RegTest(t_c, t_rule) Then
			Set t_inc = RegMatch(t_c,t_rule)
			For Each t_m In t_inc
				If LCase(t_m.SubMatches(0))="virtual" Then
					t_incFile = t_m.SubMatches(1)
				Else
					t_incFile = Mid(p_p,1,InstrRev(p_p, IIF(Instr(p_p,":")>0,"\","/"))) & t_m.SubMatches(1)
				End If
				t_incStr = incReadByFile_(t_incFile)
				t_c = Replace(t_c,t_m,t_incStr)
			Next
			Set t_inc = Nothing
		End If
		incReadByFile_ = t_c
	End Function
	
	'''由代码片段获取完整的include代码(包括内部再include)
	'p_p指定该代码片段应处在的文件夹路径
	'p_s:代码段
	'p_p:代码段应处在的文件夹路径
	Private Function incReadByCode_(Byval p_s, Byval p_p)
		Dim t_c, t_m, t_rule, t_inc, t_incFile, t_incStr
		t_c = p_s
		If IsN(t_c) Then
			Exit Function
		End If
		t_c = RegReplace(t_c, "<"&"%"&" *?@.*?%"&">", "")
		t_c = RegReplace(t_c, "(<"&"%"&"[^>]+?)(option +?explicit)([^>]*?%"&">)", "$1'$2$3")
		t_rule = "<!-- *?#include +?(file|virtual) *?= *?""??([^"":?*\f\n\r\t\v]+?)""?? *?-->"
		If RegTest(t_c,t_rule) Then
			Set t_inc = RegMatch(t_c,t_rule)
			For Each t_m In t_inc
				If LCase(t_m.SubMatches(0))="virtual" Then
					t_incFile = t_m.SubMatches(1)
				Else
					t_incFile = p_p & t_m.SubMatches(1)
				End If
				t_incStr = incReadByFile_(t_incFile)
				t_c = Replace(t_c,t_m,t_incStr)
			Next
			Set t_inc = Nothing
		End If
		incReadByCode_ = t_c
	End Function
	
	'''格式化include代码
	'p_s:要格式化的代码
	Private Function getIncCode_(Byval p_s)
		'Response.Write(p_s)
		'Response.End
		Dim t_ts, t_c, t_tc, t_sc, t_st, t_en
		'Unix到Dos
		'p_s = Replace(p_s, vbLf, vbCrLf)
		'格式化隔行/%/>/</%/这种情况,防止Select语句被非法阻断
		p_s = RegReplace(p_s, "%"&">[\n\s*\r]+<"&"%", vbCrLf)
		'Response.Write(p_s)
		'开始
		t_c = "" : t_st = 1 : t_en = Instr(p_s,"<"&"%") + 2
		t_sc = "Response.Write "
		While t_en > t_st + 1
			t_ts = Mid(p_s, t_st, t_en-t_st-2)
			t_st = Instr(t_en, p_s, "%"&">") + 2
			If Has(t_ts) Then
				t_ts = Replace(t_ts, """", """""")
				t_ts = Replace(t_ts, vbCrLf, """&vbCrLf&""")
				t_c = t_c & t_sc & """" & t_ts & """" & vbCrLf
			End If
			t_ts = Mid(p_s, t_en, t_st-t_en-2)
			t_tc = RegReplace(t_ts, "^\s*=\s*", t_sc) & vbCrLf
			t_c = t_c & t_tc
			t_en = Instr(t_st, p_s, "<"&"%") + 2
		Wend
		t_ts = Mid(p_s, t_st)
		If Has(t_ts) Then
			t_ts = Replace(t_ts, """", """""")
			t_ts = Replace(t_ts, vbcrlf, """&vbCrLf&""")
			t_c = t_c & t_sc & """" & t_ts & """" & vbCrLf
		End If
		'getIncCode_ = Core.RegReplace(t_c,"(\n\s*\r)+",vbCrLf)
		'消除空行
		getIncCode_ = RegReplace(t_c, "(\n\s*\r)+", "")
	End Function
	
	'''动态include,(模拟php的require)不含编译(可以进行逻辑判断/建议少用,性能不行)
	'p_p:文件路径
	Public Sub Require(Byval p_p)
		On Error Resume Next
		'Response.Write(p_p&"1`12`")
		'Response.Flush
		ExecuteGlobal(getIncCode_(incReadByFile_(p_p)))
		If Err.Number<>0 Then
			'抛出错误,Log信息收集
			Response.Write(getIncCode_(incReadByFile_(p_p)))
			Response.End()
			[E].Throw(21)
		End If
		'Err.Clear()
	End Sub
	
	'''动态include,含编译
	'p_p:文件路径
	Public Sub Include(Byval p_p)
		'On Error Resume Next
		ExecuteGlobal(getIncCode_(incReadByFile_(p_p)))
		If Err.Number<>0 Then
			'抛出错误,Log信息收集
			[E].Throw(21)
		End If
		'无出错后进行Include编译
		s_inccodepre = s_inccodepre & "<!--#include virtual=""" & p_p & """-->" & vbcrlf
		'Err.Clear()
	End Sub
	
	'''通过ini语言文件返回语言包代码
	'p_f:语言包ini文件路径
	Private Function lang_(Byval p_f)
		Dim t_fc : t_fc = readFile_(p_f)
		Dim t_fl : t_fl = Split(t_fc, vbcrlf)
		Dim t_c : t_c = ""
		Dim t_a, t_x
		For Each t_x In t_fl
			'含双引号情况
			If InStr(t_x, Chr(34)) > 0 Then
				t_a = Split(t_x, "=")
				If UBound(t_a) = 1 Then
					t_c = t_c & "L_" & t_a(0) & " = " & t_a(1) & vbcrlf
				End If
			Else
				'普通情况
				t_a = Split(t_x, "=")
				If UBound(t_a) = 1 Then
					t_c = t_c & "L_" & t_a(0) & " = " & Chr(34) & t_a(1) & Chr(34) & vbcrlf
				End If
			End If
		Next
		t_c = "<" & Chr(37) & vbcrlf & t_c & Chr(37) & ">"
		lang_ = t_c
	End Function
	
	'''编译生成需要的语言文件,返回插入的代码段
	'''该函数仅在生成时有效,且使用了ashapo核心fso
	'''注意该函数生成的文件使用了核心函数ReqGet
	'伪装的公用函数
	'p_s:按运行模式指定语言包编译模式(附加run模式,只返回代码段,不进行文件生成,outer模式,返回入口文件代码)
	Private Function byLang_(Byval p_s)
		If p_s = "" Then
			p_s = Lcase(C_AppStatus)
		End If
		p_s = Lcase(p_s)
		'系统是否需要编译单文件语言包
		Dim t_mf : t_mf = IsIn(p_s, Array("default", "record"))
		Dim t_dl : t_dl = Lang()
		Dim t_lp : t_lp = "/" & C_AppFolder & "/" & C_LangFolder & "/"
		Dim t_lcp : t_lcp = "/" & C_DataFolder & "/" & C_CacheFolder & "/_lang/"
		Dim t_g : t_g = s_nowG
		Dim t_m : t_m = s_nowM
		Dim t_a : t_a = s_nowA
		'default(常规)\record(日志)模式:正常生成
		Dim t_os1 : t_os1 = "<" & Chr(37) & "Select Case Lang()" & Chr(37) & ">" & vbcrlf
		'debug(调试)模式/speed(性能)模式:不生成(t_os2当返回值)
		Dim t_os2 : t_os2 = "<" & Chr(37) & "Select Case Lang()" & Chr(37) & ">" & vbcrlf
		'修正系统没有的group,防止建立不应有的语言包入口文件
		If [Fso].IsFile("/" & C_AppFolder & "/" & C_ActionFolder & "/" & t_g & "/" & t_m & C_ActionSuf & ".asp") Then
			If Not hasFunSub_(t_a, readFile_("/" & C_AppFolder & "/" & C_ActionFolder & "/" & t_g & "/" & t_m & C_ActionSuf & ".asp")) Then
				t_g = "ashapo"
			End If
		Else
			t_g = "ashapo"
		End If
		If p_s = "run" Or p_s = "outer" Then
			t_g = "ashapo"
		End If
		Dim t_i, t_fol : t_fol = [Fso].Dir(t_lp, 2)
		For t_i = 0 To UBound(t_fol,2)
			t_os1 = t_os1 & "<" & Chr(37) & "Case " & Chr(34) & Lcase(t_fol(0,t_i)) & Chr(34) & Chr(37) & ">" & vbcrlf
			t_os2 = t_os2 & "<" & Chr(37) & "Case " & Chr(34) & Lcase(t_fol(0,t_i)) & Chr(34) & Chr(37) & ">" & vbcrlf
			'开始编译生成_lang缓存文件
			'当前系统语言包,调试/性能模式下不生成
			If [Fso].IsFile("/" & C_CoreFolder & "/Lang/" & t_fol(0,t_i) & ".ini") Then
				If (Not [Fso].IsFile(t_lcp & "ashapo_" & t_fol(0,t_i) & ".asp")) And t_mf Then
					If Not [Fso].CreateFile(t_lcp & "ashapo_" & t_fol(0,t_i) & ".asp", lang_("/" & C_CoreFolder & "/Lang/" & t_fol(0,t_i) & ".ini"),0) Then
						[E].Throw(38)
					End If
				End If
				t_os1 = t_os1 & "<!--#include virtual=" & Chr(34) & t_lcp & "ashapo_" & t_fol(0,t_i) & ".asp" & Chr(34) & "-->" & vbcrlf
				t_os2 = t_os2 & lang_("/" & C_CoreFolder & "/Lang/" & t_fol(0,t_i) & ".ini") & vbcrlf
			End If
			'common.ini公用语言包
			If [Fso].IsFile(t_lp & t_fol(0,t_i) & "/common.ini") Then
				If (Not [Fso].IsFile(t_lcp & t_fol(0,t_i) & C_CacheFit & "common.asp")) And t_mf Then
					If Not [Fso].CreateFile(t_lcp & t_fol(0,t_i) & C_CacheFit & "common.asp", lang_(t_lp & t_fol(0,t_i) & "/common.ini"),0) Then
						[E].Throw(36)
					End If
				End If
				t_os1 = t_os1 & "<!--#include virtual=" & Chr(34) & t_lcp & t_fol(0,t_i) & C_CacheFit & "common.asp" & Chr(34) & "-->" & vbcrlf
				t_os2 = t_os2 & lang_(t_lp & t_fol(0,t_i) & "/common.ini") & vbcrlf
			End If
			'当前分组语言包,如index.ini
			If [Fso].IsFile(t_lp & t_fol(0,t_i) & "/" & t_g & ".ini") Then
				If (Not [Fso].IsFile(t_lcp & t_fol(0,t_i) & C_CacheFit & t_g & ".asp")) And t_mf Then
					If Not [Fso].CreateFile(t_lcp & t_fol(0,t_i) & C_CacheFit & t_g & ".asp", lang_(t_lp & t_fol(0,t_i) & "/" & t_g & ".ini"),0) Then
						[E].Throw(37)
					End If
				End If
				t_os1 = t_os1 & "<!--#include virtual=" & Chr(34) & t_lcp & t_fol(0,t_i) & C_CacheFit & t_g & ".asp" & Chr(34) & "-->" & vbcrlf
				t_os2 = t_os2 & lang_(t_lp & t_fol(0,t_i) & "/" & t_g & ".ini") & vbcrlf
			End If
		Next
		'加载当前默认语言
		t_os1 = t_os1 & "<" & Chr(37) & "Case Else" & Chr(37) & ">" & vbcrlf
		t_os2 = t_os2 & "<" & Chr(37) & "Case Else" & Chr(37) & ">" & vbcrlf
		'当前系统语言包
		If [Fso].IsFile("/" & C_CoreFolder & "/Lang/" & t_dl & ".ini") Then
			If (Not [Fso].IsFile(t_lcp & "ashapo_" & t_dl & ".asp")) And t_mf Then
				If Not [Fso].CreateFile(t_lcp & "ashapo_" & t_dl & ".asp", lang_("/" & C_CoreFolder & "/Lang/" & t_dl & ".ini"),0) Then
					[E].Throw(38)
				End If
			End If
			t_os1 = t_os1 & "<!--#include virtual=" & Chr(34) & t_lcp & "ashapo_" & t_dl & ".asp" & Chr(34) & "-->" & vbcrlf
			t_os2 = t_os2 & lang_("/" & C_CoreFolder & "/Lang/" & t_dl & ".ini") & vbcrlf
		End If
		'common.ini公用语言包
		If [Fso].IsFile(t_lp & t_dl & "/common.ini") Then
			If (Not [Fso].IsFile(t_lcp & t_dl & C_CacheFit & "common.asp")) And t_mf Then
				If Not [Fso].CreateFile(t_lcp & t_dl & C_CacheFit & "common.asp", lang_(t_lp & t_dl & "/common.ini"),0) Then
					[E].Throw(36)
				End If
			End If
			t_os1 = t_os1 & "<!--#include virtual=" & Chr(34) & t_lcp & t_dl & C_CacheFit & "common.asp" & Chr(34) & "-->" & vbcrlf
			t_os2 = t_os2 & lang_(t_lp & t_dl & "/common.ini") & vbcrlf
		End If
		'当前分组语言包,如index.ini
		If [Fso].IsFile(t_lp & t_dl & "/" & t_g & ".ini") Then
			If (Not [Fso].IsFile(t_lcp & t_dl & C_CacheFit & t_g & ".asp")) And t_mf Then
				If Not [Fso].CreateFile(t_lcp & t_dl & C_CacheFit & t_g & ".asp", lang_(t_lp & t_dl & "/" & t_g & ".ini"),0) Then
					[E].Throw(37)
				End If
			End If
			t_os1 = t_os1 & "<!--#include virtual=" & Chr(34) & t_lcp & t_dl & C_CacheFit & t_g & ".asp" & Chr(34) & "-->" & vbcrlf
			t_os2 = t_os2 & lang_(t_lp & t_dl & "/" & t_g & ".ini") & vbcrlf
		End If
		t_os1 = t_os1 & "<" & Chr(37) & vbcrlf
		t_os2 = t_os2 & "<" & Chr(37) & vbcrlf
		'结束
		t_os1 = t_os1 & "End Select" & vbcrlf
		t_os2 = t_os2 & "End Select" & vbcrlf
		t_os1 = t_os1 & Chr(37) & ">"
		t_os2 = t_os2 & Chr(37) & ">"
		Select Case p_s
		Case "run"
			If IsIn(Lcase(C_AppStatus), Array("default", "record")) Then
				byLang_ = "<!--#include virtual=" & Chr(34) & t_lcp & t_g & ".asp" & Chr(34) & "-->"
			ElseIf IsIn(Lcase(C_AppStatus), Array("debug","speed")) Then
				byLang_ = t_os2
			Else
				'其他模式出错,置空
				byLang_ = ""
			End If
		Case "outer"
			If IsIn(Lcase(C_AppStatus), Array("default", "record")) Then
				byLang_ = t_os1
			ElseIf IsIn(Lcase(C_AppStatus), Array("debug","speed")) Then
				byLang_ = t_os2
			Else
				'其他模式出错,置空
				byLang_ = ""
			End If
		Case "debug","speed"
			byLang_ = t_os2
		Case "default","record"
			'将代码段写入文件
			If Not [Fso].IsFile(t_lcp & t_g & ".asp") Then
				If Not [Fso].CreateFile(t_lcp & t_g & ".asp", t_os1,0) Then
					[E].Throw(35)
				End If
			End If
			byLang_ = "<!--#include virtual=" & Chr(34) & t_lcp & t_g & ".asp" & Chr(34) & "-->"
		End Select
	End Function
	
	'''变量预定义
	'''这是改进版的变量赋值Sign,放弃使用ExecuteGlobal，改用定义全局变量
	'''支持数组定义
	'''例参数"arr|5"表示定义名为arr的一维数组,其数组大小为6(最大可用下标5)
	'''例参数"arr|5|4"表示定义名为arr的二维数组,其数组大小为6X5
	'p_p:变量名
	Public Sub [Dim](Byval p_p)
		If InStr(p_p, "|")>0 Then
			Dim t_s, t_a, t_p
			t_a = Split(p_p, "|")
			t_s = t_a(0) & "(" & t_a(1)
			For i=2 To UBound(t_a)
				If IsNumeric(t_a(i)) Then
					t_s = t_s & "," & t_a(i)
				Else
					'本处错误代码未更新
					[E].Throw(3512)
				End If
			Next
			t_s = t_s & ")"
			t_p = t_s
			t_s = "Dim " & t_s
			's_vcodepre = s_vcodepre & t_s & vbcrlf
			'20131211为缓存格式,将变量定义解析到同一行
			If s_vcodepre = "" Then
				s_vcodepre =  t_s
			Else
				s_vcodepre = s_vcodepre & ", " & t_p
			End If
			ExecuteGlobal(t_s)
		Else
			's_vcodepre = s_vcodepre & "Dim " & p_p & vbcrlf
			'20131211为缓存格式,将变量定义解析到同一行
			If s_vcodepre = "" Then
				s_vcodepre =  "Dim " & p_p
			Else
				s_vcodepre = s_vcodepre & ", " & p_p
			End If
			ExecuteGlobal("Dim " & p_p)
		End If
	End Sub
	
	'''变量预定义
	'Assign和Dim的区别是Assign不会被格式化而每次都以ExecuteGlobal形式进行
	'Assign主要使用在跳转页面
	'使用效率上Dim>Assign,故能用Dim的地方请不要使用Assign
	'p_p:变量名
	Public Sub Assign(Byval p_p)
		If InStr(p_p, "|")>0 Then
			Dim t_str, t_arr
			t_arr = Split(p_p, "|")
			t_str = t_arr(0) & "(" & t_arr(1)
			For i=2 To UBound(t_arr)
				If IsNumeric(t_arr(i)) Then
					t_str = t_str & "," & t_arr(i)
				Else
					'本处错误代码未更新
					[E].Throw(3512)
				End If
			Next
			t_str = t_str & ")"
			t_str = "Dim " & t_str
			ExecuteGlobal(t_str)
		Else
			ExecuteGlobal("Dim " & p_p)
		End If
	End Sub
	
	'''对象预定义
	'对象有析构动作,如果采用变量预定义则析构工作无法执行
	'p_p:对象名
	Public Sub DimObject(Byval p_p)
		[Dim](p_p)
		s_inccodefix = "Set " & p_p & " = Nothing" & vbcrlf & s_inccodefix
	End Sub
	
	'''清空预定义变量
	'未启用
	Public Sub ClearDim()
		s_vcodepre = ""
	End Sub
	
	'''格式化Action代码
	'''修改c代码,除去相关的Tpl、asp等一次性使用函数
	'对:不换行的处理
	'p_s:要格式化的代码(Action类)
	Private Function formatAction_(Byval p_s)
		'删除Include调用
		's_regex.Pattern = "[Call]?[\s]*Sa.Include[\(]?""([^""]*)""[\)]?[ |	]*[:]?"
		s_regex.Pattern = "(Call[ |	]*)?Sa.Include[\(]?""([^""]*)""[\)]?[ |	]*[\:]?[ |	]*"
		p_s = s_regex.Replace(p_s,"")
		'删除Use调用
		's_regex.Pattern = "[Call]?[\s]*Sa.Use[\(]?""([^""]*)""[\)]?[ |	]*[:]?"
		s_regex.Pattern = "(Call[ |	]*)?Sa.Use[\(]?""([^""]*)""[\)]?[ |	]*[\:]?[ |	]*"
		p_s = s_regex.Replace(p_s,"")
		'删除Ext调用,已废弃
		's_regex.Pattern = "[Call]?[\s]*Sa.Ext[\(]?""([^""]*)""[\)]?[ |	]*[:]?"
		s_regex.Pattern = "(Call[ |	]*)?Sa.Ext[\(]?""([^""]*)""[\)]?[ |	]*[\:]?[ |	]*"
		p_s = s_regex.Replace(p_s,"")
		'删除Ecore调用,已废弃
		's_regex.Pattern = "[Call]?[\s]*Sa.Ecore[\(]?""([^""]*)""[\)]?[ |	]*[:]?"
		s_regex.Pattern = "(Call[ |	]*)?Sa.Ecore[\(]?""([^""]*)""[\)]?[ |	]*[\:]?[ |	]*"
		p_s = s_regex.Replace(p_s,"")
		'删除Extends调用
		's_regex.Pattern = "[Call]?[\s]*Sa.Extends[\(]?""([^""]*)""[\)]?[ |	]*[:]?"
		s_regex.Pattern = "(Call[ |	]*)?Sa.Extends[\(]?""([^""]*)""[\)]?[ |	]*[\:]?[ |	]*"
		p_s = s_regex.Replace(p_s,"")
		'删除Dim调用
		's_regex.Pattern = "[Call]?[\s]*Sa.Dim[\(|\s]{1}([^\)\n\r]*)[\)]?[^\r\n]*"
		s_regex.Pattern = "(Call[ |	]*)?Sa.Dim[\(]?""([^""]*)""[\)]?[ |	]*[\:]?[ |	]*"
		p_s = s_regex.Replace(p_s,"")
		'删除DimObject调用
		's_regex.Pattern = "[Call]?[\s]*Sa.DimObject[\(|\s]{1}([^\)\n\r]*)[\)]?[^\r\n]*"
		s_regex.Pattern = "(Call[ |	]*)?Sa.DimObject[\(]?""([^""]*)""[\)]?[ |	]*[\:]?[ |	]*"
		p_s = s_regex.Replace(p_s,"")
		'删除Display调用
		's_regex.Pattern = "[Call]?[\s]*Sa.Display[\(|\s]{1}([^\)\n\r]*)[\)]?[^\r\n]*"
		s_regex.Pattern = "(Call[ |	]*)?Sa.Display[\(]?""([^""]*)""[\)]?[ |	]*[\:]?[ |	]*"
		p_s = s_regex.Replace(p_s,"")
		'删除Show调用
		's_regex.Pattern = "[Call]?[\s]*Sa.Show[\(|\s]{1}([^\)\n\r]*)[\)]?[^\r\n]*"
		s_regex.Pattern = "(Call[ |	]*)?Sa.show[\(]?[\)]?[ |	]*[\:]?[ |	]*"
		p_s = s_regex.Replace(p_s,"")
		'删除注释
		s_regex.Pattern = "[\r\n]{1}[\s|	]*[']+[^\r\n]*"
		p_s = s_regex.Replace(p_s,"")
		'删除多余空行
		s_regex.Pattern = "\n[\s|	]*\r"
		p_s = s_regex.Replace(p_s,"")
		formatAction_ = p_s
	End Function
	
	'''往s_codefix添加代码段
	'p_s:要添加的析构代码段
	Private Sub addCodeFix_(Byval p_s)
		If s_codefix = "" Then
			s_codefix = p_s
		Else
			s_codefix = p_s & " : " & s_codefix
		End If
	End Sub
	
	'''获取格式化后的代码,用于进行ExecuteGlobal运行
	'p_s:要格式化的代码
	Private Function formatCode_(Byval p_s)
		formatCode_ = getIncCode_(incReadByCode_(p_s, ""))
	End Function
	
	'''运行原生意大利面条代码
	'伪装的公用方法
	'p_s:要运行的代码
	Private Sub run_(Byval p_s)
		'On Error Resume Next
		'Response.Write(p_s)
		'Response.End
		'Response.Write(getIncCode_(incReadByCode_(p_s, p_folderPath)))
		'Response.Flush
		ExecuteGlobal(getIncCode_(incReadByCode_(p_s, "")))
		If Err.Number<>0 Then
			'抛出错误,Log信息收集
			'直接输出查看错误
			Response.Write(getIncCode_(incReadByCode_(p_s, "")))
			Response.End
			Response.Flush
			[E].Throw(22)
		End If
		'Err.Clear()
	End Sub
	
	'''使用内置类
	'''本处Set NoThing无需在程序中手动执行
	'使用核心机制后,内置类与ashapo低耦合,可以任意添加其他类
	'p_f:类名(去掉Class)
	Public Sub Use(Byval p_f)
		'On Error Resume Next
		Dim t_fp : t_fp = "/" & C_CoreFolder & "/Class/" & p_f & "_Class.asp"
		If [Fso].IsFile(t_fp) Then
			Require(t_fp)
			ExecuteGlobal("Dim " & p_f & " : Set " & p_f & " = New " & p_f & "Class")
		Else
			'出错处理
			[E].Throw(23)
		End If
		If Err.Number<>0 Then
			'抛出错误,Log信息收集
			[E].Throw(24)
		End If
		'添加析构
		'变更为Sa公有属性则在Ashapo类中进行析构
		addCodeFix_("Set " & p_f & " = Nothing")
		'无出错后进行Use编译
		s_inccodepre = s_inccodepre & "<!--#include virtual=""/" & C_CoreFolder & "/Class/" & p_f & "_Class.asp""-->" & vbcrlf
		s_inccodepre = s_inccodepre & "<" & "%" & "Dim " & p_f & " : Set " & p_f & " = New " & p_f & "Class" & "%" & ">" & vbcrlf
		'析构在Asp类中进行一次,生成缓存后手动析构
		s_inccodefix = "Set " & p_f & " = Nothing" & vbcrlf & s_inccodefix
		'Err.Clear()
	End Sub
	
	'''伪继承
	'''多级继承的考虑
	'''本处Set NoThing应在生成的缓存文件中添加自动执行
	''伪继承文件名后缀和配置文件当前不关联,后期需要修改
	'p_f:Action类名(去掉Class)
	Public Sub Extends(Byval p_f)
		'On Error Resume Next
		Dim t_fp : t_fp = "/" & C_AppFolder & "/" & C_ActionFolder & "/" & p_f & ".class.asp"
		If [Fso].IsFile(t_fp) Then
			Require(t_fp)
			Dim t_a : t_a = Replace(p_f, "Action", "")
			ExecuteGlobal("Dim " & t_a & " : Set " & t_a & " = New " & p_f)
			'Response.Write(t_a&"111111111")
			'Response.Flush
			'Response.end
		Else
			'出错处理
			[E].Throw(25)
		End If
		If Err.Number<>0 Then
			'抛出错误,Log信息收集
			[E].Throw(26)
		End If
		'添加析构
		addCodeFix_("Set " & t_a & " = Nothing")
		'无出错后进行Extends编译
		Dim t_sp : t_sp = "/" & C_DataFolder & "/" & C_CacheFolder & "/_extends/" & p_f & ".class.asp"
		Dim t_s : t_s = formatAction_(readFile_(t_fp))
		If [Fso].IsFile(t_fp) Then
			If C_AppStatus = "default" Or C_AppStatus = "record" Then
				If Not [Fso].CreateFile(t_sp, t_s,0) Then
					[E].Throw(41)
				End If
			End If
		Else
			'Extends文件不存在，抛出错误
			[E].Throw(40)
		End If
		s_inccodepre = s_inccodepre & "<!--#include virtual=""" & t_sp & """-->" & vbcrlf
		s_inccodepre = s_inccodepre & "<" & Chr(37) & "Dim " & t_a & " : Set " & t_a & " = New " & p_f & Chr(37) & ">" & vbcrlf
		s_inccodefix = "Set " & t_a & " = Nothing" & vbcrlf & s_inccodefix
		'Err.Clear()
	End Sub
	
	'''编译Action类文件,生成缓存
	'''编译处理包括:
	'''1.Asp.Extends,处理方法:改成在缓存文件include并进行实例化(set nothing的处理)
	'''2.Asp.Use,处理方法:改成在缓存文件include并进行实例化(set nothing的处理)
	'''3.Asp.Include,目前仅支持上下文无关include,且路径必须为绝对路径
	'''4.Asp.Model,处理方法:目前未启用
	'p_p:Action类文件路径
	Private Sub byAction_(Byval p_p)
		If C_AppStatus = "debug" Or C_AppStatus = "speed" Then
			Exit Sub
		End If
		Dim t_s : t_s = formatAction_(readFile_(p_p))
		Dim t_sp : t_sp = "/" & C_DataFolder & "/" & C_CacheFolder & "/_action/" & Split(p_p, "/")(3) & "/" & Split(p_p, "/")(4)
		If Not [Fso].CreateFile(t_sp, t_s, 0) Then
			[E].Throw(41)
		End If
	End Sub
	
	'''添加cache_asp_list
	'p_p:缓存路径
	Private Sub addAspCache_(Byval p_p)
		Dim t_a,t_d,t_c : t_c = C_AspCacheAppKey
		Dim t_k : t_k = "/" & C_DataFolder & "/" & C_CacheFolder & "/cache.lock"
		'Lock文件不见了,即缓存文件被清除了
		If Not [Fso].IsFile(t_k) Then
			RemoveApp(t_c)
		End If
		If IsArray(GetApp(t_c)) Then
			If TypeName(GetApp(t_c)(0))="Dictionary" Then
				Set t_d = GetApp(t_c)(0)
				If Not t_d.Exists(p_p) Then
					t_d(p_p) = 1'其实只是要键名,赋值什么无所谓的
					'RemoveApp(t_c)
					t_a = Array(t_d)
					Call SetApp(t_c, t_a)
				End If
			Else
				Set t_d = Server.CreateObject(C_DicName)
				t_d(p_p) = 1
				t_a = Array(t_d)
				Call SetApp(t_c, t_a)
				If Not [Fso].IsFile(t_k) Then
					If Not [Fso].CreateFile(t_k, "删除ASP缓存请将该文件一并删除!",1) Then
						[E].Throw(111)
					End If
				End If
			End If
		Else
			Set t_d = Server.CreateObject(C_DicName)
			t_d(p_p) = 1
			t_a = Array(t_d)
			Call SetApp(t_c, t_a)
			If Not [Fso].IsFile(t_k) Then
				If Not [Fso].CreateFile(t_k, "删除ASP缓存请将该文件一并删除!",1) Then
					[E].Throw(111)
				End If
			End If
		End If
	End Sub
	
	'''添加cache_html_list
	'p_p:缓存路径
	Private Sub addHtmlCache_(Byval p_p)
		Dim t_a,t_d,t_c : t_c = C_HtmlCacheAppKey
		'便于程序处理的判断键名
		Dim t_e : t_e = Request.ServerVariables("SCRIPT_NAME") & "?" & Request.QueryString
		Dim t_k : t_k = "/" & C_DataFolder & "/" & C_HtmlFolder & "/html.lock"
		'Lock文件不见了,即HTML缓存文件被清除了
		If Not [Fso].IsFile(t_k) Then
			RemoveApp(t_c)
		End If
		If IsArray(GetApp(t_c)) Then
			If TypeName(GetApp(t_c)(0))="Dictionary" Then
				Set t_d = GetApp(t_c)(0)
				If Not t_d.Exists(t_e) Then
					t_d(t_e) = p_p	'键名用于判断,键值用于存储HTML路径
					'RemoveApp(t_c)
					t_a = Array(t_d)
					Call SetApp(t_c, t_a)
				End If
			Else
				Set t_d = Server.CreateObject(C_DicName)
				t_d(t_e) = p_p
				t_a = Array(t_d)
				Call SetApp(t_c, t_a)
				If Not [Fso].IsFile(t_k) Then
					If Not [Fso].CreateFile(t_k, "删除HTML缓存请将该文件一并删除!",1) Then
						[E].Throw(111)
					End If
				End If
			End If
		Else
			Set t_d = Server.CreateObject(C_DicName)
			t_d(p_p) = 1
			t_a = Array(t_d)
			Call SetApp(t_c, t_a)
			If Not [Fso].IsFile(t_k) Then
				If Not [Fso].CreateFile(t_k, "删除HTML缓存请将该文件一并删除!",1) Then
					[E].Throw(111)
				End If
			End If
		End If
	End Sub
	
	'''创建核心运行环境
	'p_s:以“,”隔开的核心文件名(不含后缀)
	Private Sub buildCore_(Byval p_s)
		If p_s = "" Then
			p_s = "Fso,Log,Tpl"
		End If
		Dim t_i,t_a : t_a = Split(p_s, ",")
		For t_i=0 To UBound(t_a)
			Require("/" & C_CoreFolder & "/Core/" & t_a(t_i) & ".asp")
			Execute("Set " & t_a(t_i) & " = New Ashapo_" & t_a(t_i) & "_Class")
		Next
	End Sub
	
	'''生成缓存文件并运行结果
	'''该函数仅在生成时有效,且使用了ashapo核心fso
	'Display应针对不同运行模式生成不同的缓存文件
	'p_tp:对应的模板文件路径
	Public Sub Display(Byval p_tp)
		Dim t_v, t_r, t_i
		If Not p_tp= "" Then
			'变更Tpl路径
			s_vtp = p_tp
		End If
		'在这里不进行,因为删除缓存会导致Server.Transfer(错误)
		'If IsIn(s_vcp, Application(C_AspCacheAppKey)) Then
		'	Server.Transfer(s_vcp)
		'	Exit Sub
		'End If
		If [Fso].IsFile(s_vcp) Then
			'''直接运行代码
			
			addAspCache_(s_vcp)
			Server.Transfer(s_vcp)
			Exit Sub
		Else
			'''如果无缓存action类文件则进行编译建立
			byAction_(s_vfp)
			'''获取v代码
			If [Fso].IsFile(s_vtp) Then
				t_v = [Fso].ReadFile(s_vtp)
				'''修改v代码,进行解析
				t_v = [Tpl].Resolve(t_v)
			Else
				t_v = ""
			End If
			'本次运行意大利面条代码
			t_r = t_v
			'''修改v代码
			Dim t_vp : t_vp = ""	'v代码的首部添加字符
			'''装入s_vcodepre
			If Not Trim(s_vcodepre) = "" Then
				t_vp = "<" & Chr(37) & Trim(s_vcodepre) & Chr(37) & ">" & vbcrlf
			End If
			'''include所需代码
			'include底层设置
			t_vp = t_vp & "<!--#include virtual=""/" & C_CoreFolder & "/Conf/config.asp""-->" & vbcrlf
			'include用户设置
			Dim t_cfg : t_cfg = Array("config", "conn", "rule", s_nowG)
			For t_i = 0 To UBound(t_cfg)
				If [Fso].IsFile("/" & C_AppFolder & "/" & C_ConfFolder & "/" & t_cfg(t_i) & ".asp") Then
					t_vp = t_vp & "<!--#include virtual=""/" & C_AppFolder & "/" & C_ConfFolder & "/" & t_cfg(t_i) & ".asp""-->" & vbcrlf
				End If
			Next
			'Dim t_cfg : t_cfg = Fso.List("/" & C_AppFolder & "/" & C_ConfFolder & "/", 1)
			'For t_i = 0 To UBound(t_cfg,2)
			'	t_vp = t_vp & "<!--#include virtual=" & Chr(34) & "/" & C_AppFolder & "/" & C_ConfFolder & "/" & t_cfg(0,t_i) & Chr(34) & "-->" & vbcrlf
			'Next
			'include会话全局变量(废弃)
			't_vp = t_vp & "<!--#include virtual=""/" & C_CoreFolder & "/Conf/session.asp""-->" & vbcrlf
			'include底层函数(函数不分先后,但是是否应将comm.asp函数提前?)
			Dim t_cf : t_cf = [Fso].Dir("/" & C_CoreFolder & "/Common/", 1)
			For t_i = 0 To UBound(t_cf,2)
				t_vp = t_vp & "<!--#include virtual=""/" & C_CoreFolder & "/Common/" & t_cf(0,t_i) & """-->" & vbcrlf
			Next
			'include语言包
			t_vp = t_vp & byLang_("") & vbcrlf
			'include Ashapo
			t_vp = t_vp & "<!--#include virtual=""/" & C_CoreFolder & "/Core/Err.asp""-->" & vbcrlf
			t_vp = t_vp & "<!--#include virtual=""/" & C_CoreFolder & "/Core/Sa.asp""-->" & vbcrlf
			t_vp = t_vp & "<" & Chr(37) & "Dim Sa : Set Sa = New Ashapo_Sa_Class" & Chr(37) & ">" & vbcrlf
			'include用户函数
			Dim t_pf : t_pf = [Fso].Dir("/" & C_AppFolder & "/" & C_CommonFolder & "/", 1)
			For t_i = 0 To UBound(t_pf,2)
				t_vp = t_vp & "<!--#include virtual=""/" & C_AppFolder & "/" & C_CommonFolder & "/" & t_pf(0,t_i) & """-->" & vbcrlf
			Next
			'include use/Include/Extends
			t_vp = t_vp & s_inccodepre
			'response.Clear
			'Response.Write(s_inccodepre)
			'response.end
			'include Action类
			t_vp = t_vp & "<!--#include virtual=""/" & C_DataFolder & "/" & C_CacheFolder & "/_action/" & s_nowG & "/" & s_nowM & C_ActionSuf & ".asp""-->" & vbcrlf
			'实例化Action
			t_vp = t_vp & "<" & Chr(37) & "Dim " & s_nowM & " : Set " & s_nowM & " = New " & s_nowM & "Action : " & s_nowM & "." & s_nowA & "()" & Chr(37) & ">"
			'''修改v代码,include缓存c代码
			t_v = t_vp & t_v
			'''析构类
			t_v = t_v & "<" & Chr(37) & vbcrlf
			'use/Include/Extends先执行
			t_v = t_v & s_inccodefix
			'主体Action
			t_v = t_v & "Set " & s_nowM & " = Nothing" & vbcrlf
			t_v = t_v & "Set Sa = Nothing" & vbcrlf
			t_v = t_v & Chr(37) & ">"
			't_v = Replace(t_v, "%" & "><" & "%" , "")
			'''删除多余空行
			's_regex.Pattern = "(\n\r)|(^\r)|(\n$)"
			's_regex.Pattern = "\n\s*\r"
			't_v = s_regex.Replace(t_v,"")
			s_regex.Pattern = "\n[\s|	]*\r"
			t_v = s_regex.Replace(t_v,"")
			'''保存修改后代码
			'Fso.FileBOM = "remove"
			Select Case Lcase(C_AppStatus)
			Case "default","record"
				If [Fso].CreateFile(s_vcp, t_v, 0) Then
					'更新cache_page_list
					addAspCache_(s_vcp)
				Else
					[E].Throw(42)
				End If
			Case "speed"
				t_v = incReadByCode_(t_v,"")
				t_v = formatAction_(t_v)
				If [Fso].CreateFile(s_vcp, t_v, 1) Then
					'更新cache_page_list
					addAspCache_(s_vcp)
				Else
					[E].Throw(42)
				End If
			End Select
			'Fso.FileBOM = "keep"
			'''结束后运行代码
			'Server.Transfer(v_cp)
			'使用Server.Transfer会导致动作二次运行,应考虑使用Asp.Run来直接运行本次解析后所得的意大利面条代码
			'使用Response.End可以阻止运行,且可以在init中加入默认Tpl.Show()动作
			run_(t_r)
			Response.End
		End If
	End Sub
	
	'''输出默认模板
	Public Sub Show()
		Display("")
	End Sub

	'''获取Success/Error页面意大利面条代码
	'模版读取顺序:
	'1.所在分组内的模板Public:Success
	'2.Public分组下的Success
	'3.主题下的Success文件
	'4.Ashapo核心Success.tpl
	'p_n:标识符(success/error)
	Private Function resultCode_(Byval p_n)
		Dim t_g : t_g = s_nowG
		Dim t_app : t_app = "%Ashapo_" & Ucase(Left(t_g,1)) & Lcase(Right(t_g, Len(t_g)-1)) & "_" & p_n & "_Code%"
		If Has(GetApp(t_app)) Then
			resultCode_ = GetApp(t_app)
		Else
			Dim t_fp : t_fp = "/" & C_AppFolder & "/" & C_TplFolder & "/" & s_nowT & "/" & t_g & "/public/" & p_n & C_TplExtSuf
			If Not [Fso].IsFile(t_fp) Then
				t_fp = "/" & C_AppFolder & "/" & C_TplFolder & "/" & s_nowT & "/public/" & p_n & C_TplExtSuf
			End If
			If Not [Fso].IsFile(t_fp) Then
				t_fp = "/" & C_AppFolder & "/" & C_TplFolder & "/" & s_nowT & "/" & p_n & C_TplExtSuf
			End If
			If Not [Fso].IsFile(t_fp) Then
				t_fp = "/" & C_CoreFolder & "/Tpl/" & p_n & ".tpl"
			End If
			resultCode_ = formatCode_([Tpl].Resolve([Fso].ReadFile(t_fp)))
			Call SetApp(t_app, resultCode_)
		End If
	End Function

	'''运行跳转页面代码
	'p_t:标识符(success/error)
	'p_m:显示的提示信息
	Private Sub resultRun_(Byval p_t, Byval p_m)
		On Error Resume Next
		Dim t_u : t_u = s_jumpUrl
		Dim t_m : t_m = p_m
		Select Case Lcase(p_t)
		Case "success"
			If s_jumpUrl = "" Then
				t_u = Request.ServerVariables("HTTP_REFERER")
			End If
		Case "error"
			If s_jumpUrl = "" Then
				t_u = ""
			End If
		Case Else
			If s_jumpUrl = "" Then
				t_u = ""
			End If
		End Select
		If t_m = "" Then
			t_m = s_message
		End If
		If p_m <> "" Then
			s_message = p_m
		End If
		Assign("T_Title") : T_Title = s_msgTitle
		Assign("T_Message") : T_Message = t_m
		Assign("T_JumpUrl") : T_JumpUrl = t_u
		Assign("T_WaitSecond") : T_WaitSecond = s_waitSecond
		'Response.Write(resultCode_(p_t))
		'Response.End
		ExecuteGlobal(resultCode_(p_t))
		If Err.Number<>0 Then
			'抛出错误,Log信息收集
			'Response.Write(resultCode_(p_t))
			'Response.Write(Err.Number)
			'Response.End
			'Response.Flush
			[E].Throw(22)
		End If
		'Err.Clear()
	End Sub
	
	'''Success页面跳转
	'p_m:显示的提示信息
	Public Sub Success(Byval p_m)
		Call resultRun_("Success", p_m)
	End Sub
	
	'''Error页面跳转
	'p_m:显示的提示信息
	Public Sub [Error](Byval p_m)
		Call resultRun_("Error", p_m)
	End Sub
	
	'''Error页面跳转
	'Response.End
	'p_m:显示的提示信息
	Public Sub ErrorE(Byval p_m)
		Call resultRun_("Error", p_m)
		Response.End
	End Sub
	
	'''底层404、500的运行代码，不含环境变量，仅解析V代码
	'p_n:标识符(404/500)
	Private Function sysRunCode_(Byval p_n)
		Dim t_p, t_v : t_v = ""
		t_p = "/" & C_AppFolder & "/" & C_TplFolder & "/" & s_nowT & "/" & p_n & C_TplExtSuf
		If Not [Fso].IsFile(t_p) Then
			'内置的404/500模板
			t_p = "/" & C_CoreFolder & "/Tpl/" & p_n & ".tpl"
		End If
		t_v = [Fso].ReadFile(t_p)
		t_v = [Tpl].Resolve(t_v)
		sysRunCode_ = t_v
	End Function
	
	'''系统底层模板是否存在，目前只有404或500(如果已存在返回true，否则进行建立，成功建立则返回true，否则返回false)
	'404为单独页面，505为include页面末端实现。
	'20131008改为在首次运行时统一建立404和505页面,必须保证本过程在模板解析之前运行
	'p_n:标识符(404/500)
	Private Function hasSysTpl_(Byval p_n)
		If Lcase(C_AppStatus)="debug" Then
			hasSysTpl_ = False
			Exit Function
		End If
		Dim t_cp : t_cp = "/" & C_DataFolder & "/" & C_CacheFolder & "/_system/page_" & p_n & ".asp"
		If [Fso].IsFile(t_cp) Then
			hasSysTpl_ = True
			Exit Function
		End If
		'当语言包无法生成成功时直接返回false
		'default/record模式下,语言包如果未生成直接返回false
		Dim t_alp : t_alp = "/" & C_AppFolder & "/" & C_LangFolder & "/"
		Dim t_clp : t_clp = "/" & C_CoreFolder & "/Lang/"
		Dim t_lcp : t_lcp = "/" & C_DataFolder & "/" & C_CacheFolder & "/_lang/"
		If IsIn(Lcase(C_AppStatus), Array("default", "record")) Then
			'底层lang
			Dim t_i,t_lf : t_lf = [Fso].Dir(t_clp, 1)
			For t_i = 0 To UBound(t_lf,2)
				If Not [Fso].CreateFile(t_lcp & "ashapo_" & [Fso].NameOfFile(t_lf(0,t_i)) & ".asp", lang_(t_clp & t_lf(0,t_i)), 0) Then
					hasSysTpl_ = False
					Exit Function
				End If
			Next
			'app各语言文件夹下common.ini
			t_lf = [Fso].Dir(t_alp, 2)
			For t_i = 0 To UBound(t_lf,2)
				If [Fso].IsFile(t_alp & t_lf(0,t_i) & "/common.ini") Then
					If Not [Fso].CreateFile(t_lcp & t_lf(0,t_i) & "_common.asp", lang_(t_alp & t_lf(0,t_i) & "/common.ini"), 0) Then
						hasSysTpl_ = False
						Exit Function
					End If
				End If
			Next
			'入口文件
			If Not [Fso].IsFile(t_lcp & "ashapo.asp") Then
				If Not [Fso].CreateFile(t_lcp & "ashapo.asp", byLang_("outer"), 0) Then
					hasSysTpl_ = False
					Exit Function
				End If
			End If
		End If
		'Response.End
		Dim  t_v : t_v = sysRunCode_(p_n)
		Select Case Cstr(p_n)
		Case "404"
			'404要加载语言包和类、函数等
			'语言包文件生成时发生错误时，理论顺序是语言包生成失败开始走500错误，500错误文件生成不了则显示底层500错误
			'当404错误发生时，进入底层文件编译流程，其他文件编译失败进入500错误，500错误文件生成不了则显示底层500错误
			'语言包文件生成应该发生在404和500之前
			'''修改v代码
			Dim t_vp : t_vp = ""	'v代码的首部添加字符
			'''include所需代码
			'include底层设置
			t_vp = t_vp & "<!--#include virtual=""/" & C_CoreFolder & "/Conf/config.asp""-->" & vbcrlf
			'include用户设置
			't_vp = t_vp & "<!--#include virtual=""/" & C_AppFolder & "/" & C_ConfFolder & "/config.asp""-->" & vbcrlf
			Dim t_cfg : t_cfg = Array("config", "conn", "rule", i_g)
			For t_i = 0 To UBound(t_cfg)
				If [Fso].IsFile("/" & C_AppFolder & "/" & C_ConfFolder & "/" & t_cfg(t_i) & ".asp") Then
					t_vp = t_vp & "<!--#include virtual=""/" & C_AppFolder & "/" & C_ConfFolder & "/" & t_cfg(t_i) & ".asp""-->" & vbcrlf
				End If
			Next
			'include底层函数
			Dim t_cf : t_cf = [Fso].Dir("/" & C_CoreFolder & "/Common/", 1)
			For i = 0 To UBound(t_cf,2)
				t_vp = t_vp & "<!--#include virtual=" & Chr(34) & "/" & C_CoreFolder & "/Common/" & t_cf(0,i) & Chr(34) & "-->" & vbcrlf
			Next
			t_vp = t_vp & byLang_("run") & vbcrlf
			'include会话全局变量(废弃)
			't_vp = t_vp & "<!--#include virtual=""/" & C_CoreFolder & "/Conf/session.asp""-->" & vbcrlf
			'include Ashapo
			t_vp = t_vp & "<!--#include virtual=""/" & C_CoreFolder & "/Core/Ashapo.asp""-->" & vbcrlf
			'include用户函数
			Dim t_pflist : t_pflist = dirList_("/" & C_AppFolder & "/" & C_CommonFolder & "/", 1)
			For i = 0 To UBound(t_pflist,2)
				t_vp = t_vp & "<!--#include virtual=""/" & C_AppFolder & "/" & C_CommonFolder & "/" & t_pflist(0,i) & """-->" & vbcrlf
			Next
			t_vp = t_vp & "<" & Chr(37) & vbcrlf
			'状态
			t_vp = t_vp & "Response.Clear" & vbcrlf
			t_vp = t_vp & "Response.Status = ""404 Not Found""" & vbcrlf
			t_vp = t_vp & Chr(37) & ">"
			'''修改v代码,include缓存c代码
			t_v = t_vp & t_v
			'''析构类
			t_v = t_v & "<" & Chr(37) & vbcrlf
			t_v = t_v & "Set Sa = Nothing" & vbcrlf
			t_v = t_v & Chr(37) & ">"
			't_v = Replace(t_v, "%" & "><" & "%" , "")
			'''删除多余空行
			's_regex.Pattern = "(\n\r)|(^\r)|(\n$)"
			s_regex.Pattern = "\n\s*\r"
			t_v = s_regex.Replace(t_v,"")
			Select Case Lcase(C_AppStatus)
			Case "default","record"
				hasSysTpl_ = [Fso].CreateFile(t_cp, t_v, 0)
			Case "speed"
				hasSysTpl_ = [Fso].CreateFile(t_cp, t_v, 1)
			End Select
		Case "500"
			'500采用include所以不用加载任何东西，但是该500页面无法单独运行
			'Do Nothing
			Select Case Lcase(C_AppStatus)
			Case "default","record"
				hasSysTpl_ = [Fso].CreateFile(t_cp, t_v, 0)
			Case "speed"
				hasSysTpl_ = [Fso].CreateFile(t_cp, t_v, 1)
			End Select
		Case ""
			'应该还是要生成一个可以直接运行的500页面
			'这个页面可以单独运行来作为系统的500页面，保持体验一致
		Case Else
			'目前不支持其他类型
			hasSysTpl_ = False
			Exit Function
		End Select
	End Function
	
	'''404页面输出
	Public Sub Go404()
		If hasSysTpl_("404") Then
			Server.Transfer("/" & C_DataFolder & "/" & C_CacheFolder & "/_system/page_404.asp")
		Else
			'应设置个开关是否发送状态
			'发送404状态
			'Response.Clear
			Response.Status = "404 Not Found"
			run_(byLang_("debug"))
			run_(sysRunCode_("404"))
			Response.End
		End If
	End Sub
	
	'''500页面输出
	'步骤:由Errc获取最后的错误代码ID,include500代码运行获得代码错误提示
	'p_eid,p_title,p_msg为空时显示已定义内容
	Public Sub Go500(Byval p_eid, Byval p_title, Byval p_msg)
		If Has(p_eid) Then
			[E].Raise(p_eid)
		End If
		If Has(p_title) Then
			s_title = p_title
		End If
		If Has(p_msg) Then
			s_msg = p_msg
		End If
		'发送500状态
		Response.Clear
		Response.Status = "500 Internal Server Error"
		If hasSysTpl_("500") Then
			Require("/" & C_DataFolder & "/" & C_CacheFolder & "/_system/page_500.asp")
		Else
			run_(sysRunCode_("500"))
		End If
		Response.End
	End Sub

	'''在生成缓存前时必须更新MAL值,缓存页面已做好更新处理
	Private Sub incAppConf_()
		Dim t_i,t_cfg : t_cfg = Array("config","conn","rule",s_nowG)
		'载入分组配置
		For t_i = 0 To UBound(t_cfg)
			If [Fso].IsFile("/" & C_AppFolder & "/" & C_ConfFolder & "/" & t_cfg(t_i) & ".asp") Then
				Require("/" & C_AppFolder & "/" & C_ConfFolder & "/" & t_cfg(t_i) & ".asp")
			End If
		Next
		'更新s_vfp/s_ccp/s_vtp
		s_vfp = "/" & C_AppFolder & "/" & C_ActionFolder & "/" & s_nowG & "/" & s_nowM & C_ActionSuf & ".asp"
		s_ccp = "/" & C_DataFolder & "/" & C_CacheFolder & "/" & s_nowG & "/" & s_nowM & C_ActionSuf & ".asp"
		s_vtp = "/" & C_AppFolder & "/" & C_TplFolder & "/" & s_nowT & "/" & s_nowG & "/" & s_nowM & "/" & s_nowA & C_TplExtSuf
	End Sub
	
	'''ashapo编译入口
	Public Sub Init__()
		'静态HTML页面先判断(自行构建HTML缓存路径,生成独立入口后再由%Ashapo_Html_Page%进行判断进而提升性能)
		Dim t_hp : t_hp = htmlPath_()
		If isFile_(t_hp) Then
			'可运行缓存HTML文件,直接执行该文件
			buildCore_("Http,Fso")
			addHtmlCache_(t_hp)
			Server.Transfer(t_hp)
		'直接使用isFile_，因为核心FSO尚未生效
		ElseIf isFile_(s_vcp) Then
			'可运行缓存文件,直接执行该文件
			buildCore_("Fso")
			addAspCache_(s_vcp)
			Server.Transfer(s_vcp)
		Else
			Set [E] = New Ashapo_Err_Class
			buildCore_("")
			incAppConf_()
			'开始编译
			'''加载编译语言包
			'Response.Write("123")
			'Response.Flush
			run_(byLang_(""))
			'Response.Write("123")
			'Response.Flush
			'''加载底层函数
			Dim t_i,t_cf : t_cf = [Fso].Dir("/" & C_CoreFolder & "/Common/", 1)
			For t_i = 0 To UBound(t_cf, 2)
				If t_cf(0, i) <> "common.asp" Then
					Require("/" & C_CoreFolder & "/Common/" & t_cf(0, t_i))
				End If
			Next
			'''加载用户函数
			Dim t_pf : t_pf = [Fso].Dir("/" & C_AppFolder & "/" & C_CommonFolder & "/", 1)
			For t_i = 0 To UBound(t_pf,2)
				Require("/" & C_AppFolder & "/" & C_CommonFolder & "/" & t_pf(0,t_i))
			Next
			'可运行缓存文件,运行该Action类(对应函数)一次,如带Display过程,则asp缓存文件已自动生成
			If [Fso].IsFile(s_vfp) Then
				'''进行函数判断,如果无该函数,则出现404错误
				Dim t_cc : t_cc = [Fso].ReadFile(s_vfp)
				If hasFunSub_(s_nowA, t_cc) Then
					Require(s_vfp)
				Else
					'如果只有视图也是可以显示的(改进)
					'运行到这步时性能已经完全下降
					'Response.Write("123")
					'Response.Flush
					Go404()
					'Response.Write("Found 404 Err On Asp.Include Ccode")
					'Response.End
				End If
			Else
				'Response.Write("Found Err On Asp.Include Ccode")
				'Response.End
				'运行到这步时性能已经完全下降
				Go404()
			End If
			'Response.Clear
			'Tpl.initIncPre_()
			ExecuteGlobal("Dim " & s_nowM & " : Set " & s_nowM & " = New " & s_nowM & "Action")
			ExecuteGlobal(s_nowM & "." & s_nowA & "()")
			'运行一次默认Tpl.Show来保证直接输出,可能被阻断而不需运行
			Show()
		End If
	End Sub
End Class
%>